package hn.cch.init;

import hn.cch.constant.Path;
import hn.cch.util.StreamUtil;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class InitParam {

    private static Logger logger = LoggerFactory.getLogger(InitParam.class);

    private static Properties properties;


    public static void initParam(File file){
        properties = new Properties();
        InputStream inputStream = StreamUtil.toInput(file);
        try {
            properties.load(inputStream);
        } catch (IOException e) {
            e.printStackTrace();
            logger.error("properties load error : " + e.getMessage());
        }
    }

    public static String getString(String key){
        String value = properties.getProperty(key);
        return value;
    }

    public static Integer getInteger(String key){
        Integer value = Integer.parseInt(getString(key));
        return value;
    }

    public static void main(String[] args) {
        initParam(new File(Path.PARAM_PATH));

        int port = getInteger("access.server.port");

        logger.info("port:" + port);


    }

}
